home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacPeople 2003 February 1
/
MACPEOPLE-2003-02-01.ISO.7z
/
MACPEOPLE-2003-02-01.ISO
/
ぶらりオンラインウェアの旅
/
おしゃべり漂流記
/
xGates
/
xGates 1.2 Source Code.sit
/
xGates 1.2 Source Code
/
main.c
< prev
next >
Wrap
Text File
|
2002-12-08
|
39KB
|
1,375 lines
/*
xGates -- Stunningly entertaining action game for MacOS Classic / MacOS X
Copyright (C) 2002 Sveinbjorn Thordarson <paladeen@soth.zoneit.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
main.c - main program file
*/
//my headers
#include "definitions.h"
#include "prototypes.h"
#include "structures.h"
#include "externs.h"
////////////////////////////////////////
//Colors
////////////////////////////////////////
RGBColor myBlackColor = { 0, 0, 0 };
RGBColor myWhiteColor = { 65535, 65535, 65535 };
RGBColor myRedColor = { 65535, 0, 0 };
RGBColor myGreenColor = { 0, 65535, 0 };
RGBColor myBlueColor = { 0, 0, 65535 };
RGBColor myVeryLightGreyColor = { 50000, 50000, 50000 };
RGBColor myLightGreyColor = { 35000, 35000, 35000 };
RGBColor myGrayColor = {16000, 16000, 16000};
RGBColor myDarkGrayColor = { 12000, 12000, 12000 };
RGBColor myGrayBlueColor = { 40000, 40000, 55000 };
////////////////////////////////////////
//rects for offworld pics to copy from
////////////////////////////////////////
Rect poofSizes[5] = { { 0, 0, 52, 42 }, { 0, 42, 52, 84 }, { 0, 84, 52, 126 }, {0, 126, 52, 168 }, { 0, 168, 52, 210 } };
Rect highscoreSize = { 0, 0, 446, 234 };
Rect gameTitleSize = { 0, 0, 91, 313 };
Rect dojSize = { 0, 0, 50, 50 };
Rect macIconSizes[2] = { { 0, 0, 37, 40 },{ 0, 40, 37, 80 } };
Rect billIconSize = { 0, 0, 40, 31 };
Rect chainsawSizes[2] = { { 0, 0, 32, 32 }, { 0, 32, 32, 64 } };
Rect cornerSize = { 0, 0, 8, 8 };
Rect chainsawBigSize = { 0, 0, 174, 300 };
Rect scoreNamePicSize = { 0, 0, 23, 146 };
Rect haukurSplashSize = { 0, 0, 281, 300 };
Rect haukurHeadSize = { 0, 0, 461, 582 };
Rect haukurWinSize = { 0, 0, 460, 323 };
Rect sothPicSize = { 0, 0, 100, 103 };
////////////////////////////////////////
//update rects for optimal drawing method
////////////////////////////////////////
Rect updateRects[kMaxUpdateRects];
short gNumUpdateRects;
Rect dojCountUpdateRect = { 465, 45, 477, 165 };
Rect billCountUpdateRect = { 465, 337, 477, 370 };
Rect scoreCountUpdateRect = { 465, 500, 477, 600 };
Rect gamePausedPicRect = { 215, 260, 245, 380 };
Rect fpsRect = { 15, 585, 35, 632 };
////////////////////////////////////////
//bill animation pics
Rect billRects[6] = { { 0, 0, 64, 50 }, { 0, 50, 64, 100 }, { 0, 100, 64, 150 }, { 0, 150, 64, 200}, { 0, 200, 64, 250}, { 0, 250, 64, 300 }};
////////////////////////////////////////
///main screen
Rect billHeadRect = { 160, 360, 260, 425 };
Rect nedHeadRect = { 115, 435, 220, 510 };
Rect chainsawRect = { 322, 332, 377, 385 };
//pic rects for blitting mac sprites
Rect macRects[10][6] ={ { { 0, 0, 52, 56}, { 0, 56, 52, 112},{ 0, 112, 52, 168}, { 0, 168, 52, 224} },
{ { 0, 0, 52, 82}, { 0, 82, 52, 164},{ 0, 164, 52, 246}, { 0, 246, 52, 328} },
{ { 0, 0, 47, 86}, { 0, 86, 47, 172},{ 0, 172, 47, 258}, { 0, 258, 47, 344} },
{ { 0, 0, 56, 82}, { 0, 86, 56, 164},{ 0, 164, 56, 246}, { 0, 246, 56, 328} },
{ { 0, 0, 58, 56}, { 0, 56, 58, 112},{ 0, 112, 58, 168}, { 0, 168, 58, 224} },
{ { 0, 0, 52, 90}, { 0, 90, 52, 180},{ 0, 180, 52, 270}, { 0, 270, 52, 360} },
{ { 0, 0, 41, 42}, { 0, 42, 41, 84}, { 0, 84, 41, 126}, { 0, 126, 41, 168} },
{ { 0, 0, 46, 50}, { 0, 50, 46, 100},{ 0, 100, 46, 150}, { 0, 150, 46, 200} },
{ { 0, 0, 33, 40}, { 0, 40, 33, 80},{ 0, 80, 33, 120}, { 0, 120, 33, 160} },
{ { 0, 0, 47, 60}, { 0, 60, 47, 120},{ 0, 120, 47, 180}, { 0, 180, 47, 240} }
};
Rect macScreenRects[10] = { { 6, 10, 31, 45 }, { 7, 11, 34, 43 }, { 7, 40, 31, 79 }, { 7, 10, 33, 45 }, { 6, 6, 32, 49 },
{ 6, 6, 35, 55 }, { 5, 9, 23, 32 }, { 3, 8, 28, 41 }, { 3, 6, 22, 33 }, { 2, 7, 31, 51 } };
//splash buttons
Rect splashButtonSizes[6] = { { 0, 0, 30, 120 }, { 30, 0, 60, 120 }, { 60, 0, 90, 120 },
{ 90, 0, 120, 120 },{ 120,0,150, 120 }, { 150, 0, 180, 120 } };
//actual onscreen rects for pics
Rect splashButtonRects[6] = { { 388, 250, 418, 370 }, { 388, 380, 418, 500 }, //new game/configure
{ 388, 510, 418, 630 },{ 428, 250, 458, 370 }, //credits/about
{ 428, 380, 458, 500 }, { 428, 510, 458, 630 } };
//start locs for bills
Point billStartLocs[8] = { { 0, 0 }, { 0,295 }, { 0, 590 }, { 198,590 }, { 396,590 }, { 396,295 }, { 396,0 }, { 198,0 } };
//app vars
short gDone = false;
short gPlaying = false;
short gWhere = 0;
//in game, glob vars
short pauseTime;
short dojCooldown = 0;
short levelScore = 0;
short cheated = false;
short currentLevel;
short currentBillSpeed;
short lastBillStartLoc;
short billsInLevel;
short levelCompleted = 0;
short numOfBills = 0;
short numOfSteves = 0;
short numOfDojs = 0;
short numOfPoofs = 0;
short weaponState = 0;
//mouse game vars
short mouseDownLast = false;
short mouseCount = 0;
short mouseCountdown = 0;
short mouseJammed = false;
//contains data about the current player
PlayerStruct player;
//game preferences
PrefsStruct prefs;
//data on Dept. of Justices in level
DojStruct dojs[2];
//poofs in level
PoofStruct poofs[kMaxPoofLimit];
//bills structure - keeps track of all bills in level
BillStruct bills[kMaxBills];
//this is the struct that keeps track of Steve. Ironically enough, it's a BillStruct
BillStruct steve;
//levels structure
LevelStruct levels[kNumOfLevels] = { // { 3, 30, 0, 2, 0, {{ kiMac, kMacOS, 230, 180 }, { kiMac, kMacOS, 280, 245 }, { kiMac, kMacOS, 330, 180} } },
{ 3, 40, 0, 3, 0,{{ kiMac, kMacOS, 230, 245, 0 }, { kiMac, kMacOS, 330, 245 }, { kYosemite, kMacOS, 280, 180} } },
{ 4, 45, 0, 4, 0,{{ kYosemite, kMacOS, 190,210, 0}, { kYosemite, kMacOS, 250, 300 }, { kSawtooth, kMacOS, 300, 220}, { kYosemite, kMacOS, 350, 160} } },
{ 3, 50, 1, 3, 1,{{ kiMac, kMacOS, 220, 218, 0 }, { kSawtooth, kMacOS, 300, 190 }, { kYosemite, kMacOS, 300, 260} } },
{ 5, 55, 0, 3, 1,{{ kSawtooth,kMacOS, 183, 160}, { kSawtooth, kMacOS, 187, 250 }, { kCube, kMacOS, 295, 195}, { kSawtooth, kMacOS, 395, 160}, { kSawtooth, kMacOS, 380, 260} } },
//{ 3, 40, 0, 4, 1,{{ kCube, kMacOS, 230, 180 }, { kSawtooth, kMacOS, 280, 260 }, { kCube, kMacOS, 330, 190} } },
{ 4, 60, 0, 5, 1,{{ kiBook, kMacOS, 180, 160, 0 }, { kYosemite, kMacOS, 295, 195 }, { kiBook, kMacOS, 280, 275}, { kiBook, kMacOS, 395, 160} } },
{ 3, 65, 1, 3, 2,{{ kiBook, kMacOS, 360, 200, 0 }, { kNewiMac, kMacOS, 250, 180 }, { kPismo, kMacOS, 225, 265} } },
{ 5, 70, 0, 4, 2,{{ kiBook, kMacOS, 200, 160, 0 }, { kiBook, kMacOS, 400, 160 }, { kNewiMac, kMacOS, 284, 195 }, { kPismo, kMacOS, 195, 265}, { kPismo, kMacOS, 385, 265} } },
{ 3, 75, 0, 5, 2,{{ kSawtooth, kMacOS, 184,152, 0}, { kQuicksilver, kMacOS, 252, 213}, { kSawtooth, kMacOS, 340, 270} } },
{ 4, 80, 1, 6, 2,{{ kNewiMac, kMacOS, 272, 255, 0}, { kQuicksilver, kMacOS, 220, 196}, { kQuicksilver, kMacOS, 315, 196}, { kNewiMac, kMacOS, 272, 134} } },
{ 3, 85, 0, 3, 2,{{ kSawtooth, kMacOS, 180,152, 0}, { kQuicksilver, kMacOS, 270, 200}, { kYosemite, kMacOS, 360, 260} } },
{ 5, 90, 0, 4, 2,{{ kiBook, kMacOS, 266, 138, 0 }, { kQuicksilver, kMacOS, 305, 185}, { kQuicksilver, kMacOS, 200, 185 }, { kPismo, kMacOS, 237, 265}, { kiMac, kMacOS, 385, 265} } },
{ 2, 95, 1, 5, 3,{{ kTiBook, kMacOS, 190,180, 0 }, { kTiBook, kMacOS, 390, 180 } } },
{ 5, 100, 0, 4, 3,{{ kNewiBook, kMacOS, 200,140, 0}, { kNewiBook, kMacOS, 400, 140 }, { kQuicksilver, kMacOS, 275, 195}, { kNewiBook, kMacOS, 200,270}, { kNewiBook, kMacOS, 400, 270} } },
{ 3, 105, 0, 3, 3,{{ kCube, kMacOS, 170,195, 0 }, { kQuicksilver, kMacOS, 280, 210}, { kCube, kMacOS, 390, 195} } },
{ 4, 110, 1, 3, 3,{{ kCube, kMacOS, 215, 170, 0 }, { kCube, kMacOS, 335, 170 }, { kQuicksilver, kMacOS, 215, 235}, { kQuicksilver, kMacOS, 335, 235} } },
{ 3, 115, 0, 4, 3,{{kQuicksilver,kMacOS,275,135, 0}, { kQuicksilver, kMacOS,275,205 }, { kQuicksilver, kMacOS, 275, 275} } },
{ 5, 120, 0, 5, 4,{{ kNewiMac,kMacOS, 183, 160, 0 }, { kNewiMac, kMacOS, 187, 250 }, { kTiBook, kMacOS, 295, 195}, { kNewiMac, kMacOS, 395, 160}, { kNewiMac, kMacOS, 380, 260} } },
//{ 2, 80, 1, 3, 4,{{ kNewiBook, kMacOS, 265,180}, { kNewiBook, kMacOS, 315, 180 } } },
{ 3, 125, 1, 4, 4,{{ kiMac,kMacOS, 190,220, 0 }, { kNewiMac, kMacOS,275,150 }, { kiMac, kMacOS, 390, 220} } },
{ 6, 130, 0, 4, 4,{{ kiMac, kMacOS, 150, 150, 0 }, { kiMac, kMacOS, 275, 150 }, { kiMac, kMacOS, 400, 150 }, { kiMac, kMacOS, 150, 270}, { kiMac, kMacOS, 275, 270},{ kiMac, kMacOS, 400, 270} } },
{ 4, 135, 0, 5, 4,{{ kYosemite, kMacOS, 170,180, 0}, { kYosemite, kMacOS, 350, 180 }, { kYosemite, kMacOS, 205, 244}, { kYosemite, kMacOS, 305, 244} } },
{ 2, 140, 1, 2, 5,{{ kPismo, kMacOS, 280,180, 0 }, { kPismo, kMacOS, 270, 240 } } },
//{ 3, 90, 0, 3, 5,{{ kNewiBook,kMacOS, 195,230 }, { kSawtooth, kMacOS,255,175 }, { kNewiBook, kMacOS, 390, 150} } },
//{ 4, 95, 0, 4, 5,{{ kCube, kMacOS, 215, 170 }, { kCube, kMacOS, 335, 170 }, { kQuicksilver, kMacOS, 215, 235}, { kQuicksilver, kMacOS, 335, 235} } },
{ 4, 145, 0, 3, 5,{{ kSawtooth, kMacOS, 170,205, 0}, { kCube, kMacOS, 370, 205 }, { kQuicksilver, kMacOS, 260, 147}, { kYosemite, kMacOS, 270, 250} } },
{ 6, 150, 0, 4, 5,{{ kiMac, kMacOS, 150, 140 , 0 }, { kYosemite, kMacOS, 380, 150 }, { kSawtooth, kMacOS, 240, 150 },{ kCube, kMacOS, 150, 270},{ kNewiMac, kMacOS, 275, 270},{ kQuicksilver,kMacOS, 400, 270} }},
{ 4, 155, 1, 4, 5,{{ kiBook, kMacOS, 170,195, 0 }, { kPismo, kMacOS, 230, 210}, { kNewiBook, kMacOS, 310, 185},{ kTiBook, kMacOS, 410, 195} } }
};
FSSpec prefsFile;
Rect gameScreenSize = { 0, 0, 460, 640 };
Rect barRect = { 460, 0, 480, 640 };
Rect winRect = { 100, 100, 580, 740 };
Rect screenSize = { 0, 0, 480, 640 };
Boolean gOS;
//menus
MenuHandle appleMenu;
MenuHandle fileMenu;
MenuHandle editMenu;
MenuHandle optionsMenu;
MenuHandle geekOptionsMenu;
PixMapHandle billPix;
GWorldPtr billPtr;
PixMapHandle stevePix;
GWorldPtr stevePtr;
PixMapHandle workMapPix;
GWorldPtr workMapPtr;
PixMapHandle macPix[10];
GWorldPtr macPtr[10];
PixMapHandle chainSawPix;
GWorldPtr chainSawPtr;
PixMapHandle chainSawBigPix;
GWorldPtr chainSawBigPtr;
PixMapHandle splashPix;
GWorldPtr splashPtr;
PixMapHandle highScorePix;
GWorldPtr highScorePtr;
PixMapHandle buttonsPix;
GWorldPtr buttonsPtr;
PixMapHandle deptOfJusticePix;
GWorldPtr deptOfJusticePtr;
PixMapHandle macIconPix;
GWorldPtr macIconPtr;
PixMapHandle billIconPix;
GWorldPtr billIconPtr;
PixMapHandle deptOfJusticeIconPix;
GWorldPtr deptOfJusticeIconPtr;
PixMapHandle poofPix;
GWorldPtr poofPtr;
PixMapHandle sothPix;
GWorldPtr sothPtr;
PixMapHandle mousePix;
GWorldPtr mousePtr;
PixMapHandle keyboardPix;
GWorldPtr keyboardPtr;
PixMapHandle gamePausedPix;
GWorldPtr gamePausedPtr;
PixMapHandle cornerPix[2];
GWorldPtr cornerPtr[2];
PixMapHandle scoreNameRectPix;
GWorldPtr scoreNameRectPtr;
PixMapHandle haukurSplashPix;
GWorldPtr haukurSplashPtr;
PixMapHandle haukurHeadPix;
GWorldPtr haukurHeadPtr;
PixMapHandle haukurWinPix;
GWorldPtr haukurWinPtr;
PixMapHandle sothGuysPix;
GWorldPtr sothGuysPtr;
//SOUNDS
//weapon sounds
Handle chainsawSnd;
Handle jammedSnd;
//bill sounds
Handle billScreamSnd;
Handle billLaughSnd;
Handle billIndignantSnd;
Handle billBriefcaseSnd;
//steve sounds
Handle steveAppearsSnd;
Handle steveScreamSnd;
Handle steveInstallsSnd;
//computer sounds
Handle macOSLoadedSnd;
Handle winXPLoadedSnd;
//dept of justice sounds
Handle dojUsedSnd;
Handle dojAppearsSnd;
Handle dojCaughtSnd;
//other sounds
Handle bonkSnd;
Handle zoomSnd;
Handle poofSnd;
Handle gongSnd;
Handle beepSnd;
//game sounds
Handle gameOverSnd;
Handle gamePausedSnd;
Handle yeahSnd;
Handle killSomeBillSnd;
Handle goodJobSound;
//music sounds
Handle musicSounds[6];
//game sound channels
SndChannelPtr weaponSndChannel;
SndChannelPtr billSndChannel;
SndChannelPtr steveSndChannel;
SndChannelPtr computerSndChannel;
SndChannelPtr dojSndChannel;
SndChannelPtr otherSndChannel;
//music channel
SndChannelPtr musicSndChannel;
Rect textFieldRect = { 360, 50, 377, 190 };
TEHandle playerNameTextField;
Str255 playerName;
DSpContextReference gDisplayContext;
DSpContextAttributes gDisplayAttributes;
//////////////////////////////////////////////////////
//main program function. Init and enter event loop
//////////////////////////////////////////////////////
int main(void)
{
EventRecord theEvent;
long caretTime = GetCaretTime();//get caret time in case of text blinking
Boolean wasProcessed;
//load OS stuff
InitToolbox();
//read preferences file
LoadPrefs();
DisplayInit();
//install apple event handlers
AppleEventInit();
//install menus
InitMenus();
//load pixmaps to memory
InitGraphics();
//load sound resources and channels
InitSound();
HideCursor();
//draw soth screen
DrawSothScreen();
BlitWorkMapToScreen();
//play gong
if (prefs.sound)
{
SndPlay(otherSndChannel, (SndListHandle)gongSnd, true);
}
Sleep(80);
//zoom out to splash screen
DoSplashScreen();
ShowCursor();
//define starting location
gWhere = kSplashScreen;
//begin application event loop
do
{
if(gPlaying == true && gWhere == kPlayingGame)
{
DoGameFrame();
}
else
{
WaitNextEvent(everyEvent, &theEvent, caretTime, nil);
DSpProcessEvent (&theEvent, &wasProcessed);
if (!wasProcessed)
HandleEvent(&theEvent);
SetMenuStatus();
//blinking text insert if we're in highscore entry
if (gWhere == kHighScore)
TEIdle(playerNameTextField);
}
} while (!gDone);
QuitApp();
return(0);
}
//////////////////////////////////////////////////////
//Clean up and exit application
//////////////////////////////////////////////////////
void QuitApp (void)
{
//save preferences
WritePrefs();
gDone = true;
//silence
SilenceAllChannels();
DSpShutdown();
//exit
ExitToShell();
}
//////////////////////////////////////////////////////
//Determine which menus are active, which items are checked, etc
//////////////////////////////////////////////////////
void SetMenuStatus (void)
{
if(gPlaying)
{
DisableMenuItem(appleMenu, 1);
DisableMenuItem(fileMenu, 1);
DisableMenuItem(fileMenu, 4);
DisableMenuItem(fileMenu, 5);
DisableMenuItem(fileMenu, 6);
DisableMenuItem(fileMenu, 7);
DisableMenuItem(fileMenu, 8);
DisableMenuItem(fileMenu, 9);
EnableMenuItem(fileMenu, 2);
//options menu
EnableMenuItem(optionsMenu, 8);
if (gWhere == kGamePaused)
{
CheckMenuItem(optionsMenu, 5, 1);
}
else
{
CheckMenuItem(optionsMenu, 5, 0);
}
//geek options menu
EnableMenuItem(geekOptionsMenu, 1);
EnableMenuItem(geekOptionsMenu, 3);
EnableMenuItem(geekOptionsMenu, 5);
if (prefs.fixedFrameRate)
{
EnableMenuItem(geekOptionsMenu, 6);
EnableMenuItem(geekOptionsMenu, 7);
EnableMenuItem(geekOptionsMenu, 8);
}
else
{
DisableMenuItem(geekOptionsMenu, 6);
DisableMenuItem(geekOptionsMenu, 7);
DisableMenuItem(geekOptionsMenu, 8);
}
EnableMenuItem(geekOptionsMenu, 10);
DisableMenuItem(geekOptionsMenu, 12);
}
else if (gWhere == kHighScore)
{
//file menu
DisableMenuItem(fileMenu, 1);
DisableMenuItem(fileMenu, 2);
DisableMenuItem(fileMenu, 3);
DisableMenuItem(fileMenu, 4);
DisableMenuItem(fileMenu, 5);
DisableMenuItem(fileMenu, 6);
DisableMenuItem(fileMenu, 7);
DisableMenuItem(fileMenu, 8);
DisableMenuItem(fileMenu, 9);
//options menu
DisableMenuItem(optionsMenu, 5);
//geek options menu
DisableMenuItem(geekOptionsMenu, 1);
DisableMenuItem(geekOptionsMenu, 3);
DisableMenuItem(geekOptionsMenu, 5);
DisableMenuItem(geekOptionsMenu, 6);
DisableMenuItem(geekOptionsMenu, 7);
DisableMenuItem(geekOptionsMenu, 8);
EnableMenuItem(geekOptionsMenu, 10);
DisableMenuItem(geekOptionsMenu, 12);
}
else
{
EnableMenuItem(appleMenu, 1);
//file menu
EnableMenuItem(fileMenu, 1);
EnableMenuItem(fileMenu, 4);
EnableMenuItem(fileMenu, 5);
EnableMenuItem(fileMenu, 6);
EnableMenuItem(fileMenu, 7);
EnableMenuItem(fileMenu, 8);
EnableMenuItem(fileMenu, 9);
DisableMenuItem(fileMenu, 2);
//options menu
DisableMenuItem(optionsMenu, 5);
//geek options menu
EnableMenuItem(geekOptionsMenu, 1);
EnableMenuItem(geekOptionsMenu, 3);
EnableMenuItem(geekOptionsMenu, 5);
if (prefs.fixedFrameRate)
{
EnableMenuItem(geekOptionsMenu, 6);
EnableMenuItem(geekOptionsMenu, 7);
EnableMenuItem(geekOptionsMenu, 8);
}
else
{
DisableMenuItem(geekOptionsMenu, 6);
DisableMenuItem(geekOptionsMenu, 7);
DisableMenuItem(geekOptionsMenu, 8);
}
EnableMenuItem(geekOptionsMenu, 10);
if (gWhere == kSplashScreen)
EnableMenuItem(geekOptionsMenu, 12);
}
//checkmarks in the right places
//option menu
if (prefs.sound)
CheckMenuItem(optionsMenu, 1, true);
else
CheckMenuItem(optionsMenu, 1, false);
if (prefs.music)
CheckMenuItem(optionsMenu, 2, true);
else
CheckMenuItem(optionsMenu, 2, false);
//geek options menu
if (prefs.noChainsawJamming)
CheckMenuItem(geekOptionsMenu, 1, true);
else
CheckMenuItem(geekOptionsMenu, 1, false);
if (prefs.fixedFrameRate)
CheckMenuItem(geekOptionsMenu, 3, true);
else
CheckMenuItem(geekOptionsMenu, 3, false);
if (prefs.drawFPS)
CheckMenuItem(geekOptionsMenu, 4, true);
else
CheckMenuItem(geekOptionsMenu, 4, false);
}
#pragma mark -
//////////////////////////////////////////////////////
//Event controller, really
//////////////////////////////////////////////////////
void HandleEvent (EventRecord *myEvent)
{
switch(myEvent->what)
{
case keyDown:
case autoKey:
HandleKey(myEvent);
break;
case kHighLevelEvent:
HandleHLEvent(myEvent);
break;
case activateEvt:
break;
case updateEvt:
HandleUpdate();
break;
case mouseDown:
HandleMouse(myEvent);
break;
case osEvt:
HandleOSEvent(myEvent);
break;
}
}
//////////////////////////////////////////////////////
//Handle OS events
//////////////////////////////////////////////////////
void HandleOSEvent (EventRecord *myEvent)
{
if (myEvent->message & 0x01000000) //・ Suspend/resume event
{
if (myEvent->message & 0x00000001) //・ Resume
{
}
else
{
EventRecord theEvent;
while (true)
{
//・ Only check for resume and update events. While doing so, give TONS of time to other apps
if (WaitNextEvent(osMask, &theEvent, 32767, nil))
{
if (theEvent.message & 0x01000000) //・ Suspend/resume event
{
if (theEvent.message & 0x00000001) //・ Resume
{
Boolean dummy;
//・ Make sure that DrawSprocket knows that we've resumed
DSpProcessEvent(&theEvent, &dummy);
}
break;
}
}
}
HandleUpdate();
}
}
}
//////////////////////////////////////////////////////
//Handle key stroke events
//////////////////////////////////////////////////////
void HandleKey (EventRecord *theEvent)
{
long menuChoice;
char theKey;
long strLen = 0;
theKey = (char)(theEvent->message & charCodeMask);
//just do the menu shortcut key command
if (theEvent->modifiers & cmdKey)
{
menuChoice = MenuKey(theKey);
if (HiWord(menuChoice))
{
HandleMenus(menuChoice);
HiliteMenu(menuChoice);
}
}
//IF WE'RE ASKING FOR NAME FOR HIGH SCORE CHART
if (gWhere == kHighScore)
{
//if enter button is pressed, highlight OK and close
if ( (theKey == (char)13) || (theKey == (char)3))
{
strLen = (**playerNameTextField).teLength;
if (strLen < 1)
{
if (prefs.sound)
{
SilenceChannel(billSndChannel);
SndPlay(billSndChannel, (SndListHandle)billScreamSnd, true);
return;
}
}
//add player into list and adjust
AddScoreToHighScoreChart();
TEDeactivate(playerNameTextField);
TEDispose(playerNameTextField);
EndGame();
}
else
{
strLen = (*playerNameTextField)->teLength;
if (theKey == 8)//delete
{
TEKey(theKey, playerNameTextField);
}
else if (strLen < 15)
{
TEKey(theKey, playerNameTextField);
}
else
{
if (prefs.sound)
{
SilenceChannel(billSndChannel);
SndPlay(billSndChannel, (SndListHandle)billScreamSnd, true);
}
}
}
}
//IF PAUSED
if (gWhere == kGamePaused && theKey == 'q')
{
GameOver();
}
if (gOS == kMacOSX && (gWhere == kSplashScreen) )
{
if (theKey == 'q')
{
QuitApp();
}
}
}
//////////////////////////////////////////////////////
////Process Apple Events
//////////////////////////////////////////////////////
void HandleHLEvent (EventRecord *myEvent)
{
AEProcessAppleEvent(myEvent);
}
//////////////////////////////////////////////////////
////Handle menu selection
//////////////////////////////////////////////////////
void HandleMenus(long menuChoice)
{
short menuID = HiWord(menuChoice);
short menuItem = LoWord(menuChoice);
switch (menuID)
{
//Apple Menu
case 128:
{
switch(menuItem)
{
case 1:
DoCredits();
break;
default:
break;
}
}
break;
//File Menu
case 1001:
switch(menuItem)
{
//Start game
case 1:
NewGame();
break;
//End game
case 2:
GameOver();
break;
//seperator
case 3:
break;
//Clear high score
case 4:
if (prefs.sound)
{
SndPlay(computerSndChannel, (SndListHandle)winXPLoadedSnd, true);
}
ClearHighscoreList();
DrawSplashScreen();
BlitWorkMapToScreen();
break;
case 5: //seperator
break;
case 6://about
DoAbout();
break;
//Controls
case 7:
DoControls();
break;
//Credits
case 8:
DoCredits();
break;
//Disclaimer
case 9:
DoDisclaimer();
break;
case 10:
break;
//quit
case 11:
gDone = true;
break;
}
break;
//Edit Menu
case 1002:
break;
//Options Menu
case 1003:
switch(menuItem)
{
//sound effects
case 1:
prefs.sound = !prefs.sound;
break;
//music
case 2:
prefs.music = !prefs.music;
break;
//seperaotr
case 3:
break;
case 4://fullscreen
if (IsMenuBarVisible())
{
HideMenuBar();
if (gWhere == kSplashScreen)
{
DrawSplashScreen();
}
}
else
{
ShowMenuBar();
/*if (gWhere == kSplashScreen)
{
DrawSplashScreen();
}*/
}
break;
case 5://change res
if (gWhere != kGamePaused)
{
PauseGame();
}
else
{
EndPause();
}
break;
}
break;
case 1004:
switch(menuItem)
{
case 1:
//No Chainsaw Jamming
prefs.noChainsawJamming = !prefs.noChainsawJamming;
if (prefs.noChainsawJamming)
DoAlert("¥pNotification!", "¥pDisabling Chainsaw Jamming prevents entrance to the High Score Chart.");
break;
//Seperator
case 2:
break;
//Fixed Framerate
case 3:
prefs.fixedFrameRate = !prefs.fixedFrameRate;
if (!prefs.fixedFrameRate)
DoAlert("¥pWarning", "¥pTurning off Fixed Frame Rate may result in the game being unplayable if you have a decently fast system.");
break;
//framerate 15
case 4:
prefs.drawFPS = !prefs.drawFPS;
break;
//seperator
case 5:
break;
//Max FPS report
case 6:
break;
}
break;
}
DrawMenuBar();
}
//////////////////////////////////////////////////////
////Handle general mouse activity
//////////////////////////////////////////////////////
void HandleMouse (EventRecord *myEvent)
{
long menuChoice;
short windowPart;
WindowPtr hitWindow;
//if we're in MacOS X, it doesnォt register the DrawSprockets screen as a window
//hence, we just handle the click in global coordinates and we know it was in
//content since it's not possible to press anything else
if (gOS == kMacOSX)
{
HandleClick(myEvent->where);
return;
}
//get window in which it occurred
windowPart = FindWindow(myEvent->where, &hitWindow);
switch (windowPart)
{
//menu
case inMenuBar:
menuChoice = MenuSelect(myEvent->where);
if (menuChoice)
{
HandleMenus(menuChoice);
}
HiliteMenu(0);
break;
//within window
case inContent:
GlobalToLocal(&myEvent->where);
HandleClick(myEvent->where);
break;
//There is no close box
//close box pressed
/*case inGoAway:
QuitApp();
break;*/
}
}
//////////////////////////////////////////////////////
////Respond to click in content screen
//////////////////////////////////////////////////////
void HandleClick (Point where)
{
short i;
switch(gWhere)
{
case kSplashScreen:
for (i = 0; i < 6; i++)
{
if (PtInRect(where, &splashButtonRects[i]))
{
ShadeRect(&splashButtonRects[i]);
while (Button())
{
}
switch(i)
{
case 0://new game
NewGame();
break;
case 1://configure
DoControls();
break;
case 2://about
DoAbout();
break;
case 3://credits
DoCredits();
break;
case 4://disclaimer
DoDisclaimer();
break;
case 5://quit
QuitApp();
break;
}
}
}
if (PtInRect(where, &billHeadRect))
{
if (prefs.sound)
{
SilenceChannel(otherSndChannel);
SndPlay(otherSndChannel, (SndListHandle)billScreamSnd, true);
}
}
if (PtInRect(where, &nedHeadRect))
{
if (prefs.sound)
{
SilenceChannel(otherSndChannel);
SndPlay(otherSndChannel, (SndListHandle)yeahSnd, true);
}
}
if (PtInRect(where, &chainsawRect))
{
if (prefs.sound)
{
SilenceChannel(otherSndChannel);
SndPlay(otherSndChannel, (SndListHandle)chainsawSnd, true);
}
}
break;
case kAbout:
DoMoreAbout();
break;
case kMoreAbout:
DoSplashScreen();
break;
case kDisclaimer:
DoSplashScreen();
break;
case kCredits:
DoSplashScreen();
break;
case kControls:
DoSplashScreen();
break;
case kGamePaused:
//if the pause cooldown period has completed, we return to game
i = TickCount();
if (i - pauseTime > kPauseCooldown)
{
EndPause();
}
break;
case kHighScore:
if (PtInRect(where, &textFieldRect))
{
TEClick(where, false, playerNameTextField);
}
break;
case kGameWon:
//OK, the player has won the game. He clicked.
//Now, let's check if he made it to the highscore
if (!Button())
return;
player.place = CheckPlaceInHighscoreList();
//player made it on high score list
if (player.place < 16)
{
if (prefs.sound)
{
SndPlay(otherSndChannel, (SndListHandle)yeahSnd, true);
}
DoGetPlayerName();
}
else
{
EndGame();
}
break;
case kPerformance:
DoSplashScreen();
break;
}
}
//////////////////////////////////////////////////////
////Update screen contents by drawing current workmap
//////////////////////////////////////////////////////
void HandleUpdate (void)
{
CGrafPtr frontBuffer, backBuffer;
DSpContext_GetFrontBuffer(gDisplayContext, &frontBuffer);
DSpContext_GetBackBuffer(gDisplayContext, kDSpBufferKind_Normal, &backBuffer);
//BeginUpdate((WindowRef) theWindow);
SetPort(frontBuffer);
CopyBits(GetPortBitMapForCopyBits(backBuffer), GetPortBitMapForCopyBits(frontBuffer), &screenSize, &screenSize, srcCopy, nil);
//EndUpdate((WindowRef) theWindow);
if (gWhere == kHighScore)
TEUpdate (&textFieldRect, playerNameTextField);
}
#pragma mark -
//////////////////////////////////////////////////////
////Go to all the different game screens
//////////////////////////////////////////////////////
void DoAbout (void)
{
DrawAboutScreen();
gWhere = kAbout;
//play zoom sound
if (prefs.sound)
{
SilenceChannel(otherSndChannel);
SndPlay(otherSndChannel, (SndListHandle)zoomSnd, true);
}
ZoomBlitWorkMapToScreen();
}
void DoMoreAbout (void)
{
DrawMoreAboutScreen();
gWhere = kMoreAbout;
//play zoom sound
if (prefs.sound)
{
SilenceChannel(otherSndChannel);
SndPlay(otherSndChannel, (SndListHandle)zoomSnd, true);
}
ZoomBlitWorkMapToScreen();
}
void DoDisclaimer (void)
{
DrawDisclaimerScreen();
gWhere = kDisclaimer;
//play zoom sound
if (prefs.sound)
{
SilenceChannel(otherSndChannel);
SndPlay(otherSndChannel, (SndListHandle)zoomSnd, true);
}
ZoomBlitWorkMapToScreen();
}
void DoCredits (void)
{
gWhere = kCredits;
DrawCreditsScreen();
//play zoom sound
if (prefs.sound)
{
SilenceChannel(otherSndChannel);
SndPlay(otherSndChannel, (SndListHandle)zoomSnd, true);
}
ZoomBlitWorkMapToScreen();
}
void DoControls (void)
{
DrawControlsScreen();
gWhere = kControls;
//play zoom sound
if (prefs.sound)
{
SilenceChannel(otherSndChannel);
SndPlay(otherSndChannel, (SndListHandle)zoomSnd, true);
}
ZoomBlitWorkMapToScreen();
}
void DoSplashScreen (void)
{
DrawSplashScreen();
gWhere = kSplashScreen;
if (prefs.sound)
{
SilenceChannel(otherSndChannel);
SndPlay(otherSndChannel, (SndListHandle)zoomSnd, true);
}
ZoomBlitWorkMapToScreen();
DrawMenuBar();
}
#pragma mark -
//////////////////////////////////////////////////////
////Reset the highscore settings to default
//////////////////////////////////////////////////////
void ClearHighscoreList (void)
{
short i;
for (i = 0; i < 16; i++)
{
pStrcpy(prefs.highscores.name[i], kDefaultName);
prefs.highscores.score[i] = 160-(i*10);
}
prefs.lastHighScore = kNoHighScoreSet;
}
#pragma mark -
//APPLE EVENT STUFF
//////////////////////////////////////////////////////
////Handle an Apple Event Quit. We ignore the rest
//////////////////////////////////////////////////////
OSErr HandleAEQuitApp(const AppleEvent *theAppleEvent, AppleEvent *reply, long refCon)
{
QuitApp();
return MyGotRequiredParams(theAppleEvent);
}
void AppleEventInit(void)
{
AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP((AEEventHandlerProcPtr)HandleAEQuitApp), 0L, false);
}
OSErr MyGotRequiredParams(const AppleEvent *theAppleEvent)
{
DescType returnedType;
Size actualSize;
if ( AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard, &returnedType, nil, 0, &actualSize) == errAEDescNotFound )
{
return noErr;
}
else
{
return errAEParamMissed;
}
}